package com.ldj.rocketmq.producer;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

/**
 * User: ldj
 * Date: 2024/3/26
 * Time: 2:26
 * Description: 单向消息生产者 简单场景：如发送日志
 */
public class OneWayProducer {

    public static void main(String[] args) {

        String msg = "我要和你来一场浪漫之旅！";
        DefaultMQProducer producer = new DefaultMQProducer("produce-group1");
        producer.setNamesrvAddr("192.168.208.190:9876;192.168.208.191:9876;192.168.208.192:9876");
        try {
            producer.start();
            for (int i = 0; i < 10; i++) {
                producer.sendOneway(new Message("love_letter", "appointment", (msg + i).getBytes(StandardCharsets.UTF_8)));
            }
            System.out.println("消息已发送完毕！");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            producer.shutdown();
        }
    }
}
